<!DOCTYPE html>
<html>
    {% load static %}
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

		<title>验证邮箱</title>

		<link href="{% static 'assets/css/admin.css' %}" rel="stylesheet" type="text/css">
		<link href="{% static 'assets/css/amazeui.css' %}" rel="stylesheet" type="text/css">

		<link href="{% static 'css/personal.css' %}" rel="stylesheet" type="text/css">
		<link href="{% static 'css/stepstyle.css' %}" rel="stylesheet" type="text/css">

		<script type="text/javascript" src="{% static 'js/jquery-1.7.2.min.js' %}"></script>
		<script src="{% static 'assets/js/amazeui.js' %}"></script>
        <script type="text/javascript">
        $(function() {

           //邮箱验证码
            //1. 找标签:btn1
            //2. 定时器完成: 显示时间变化!!!
            //setInterval(函数, 时间)
            //3.难点: 定时器中函数,不断减1, 见到<0终止!!!!
            var btn1 = $('#sendsmss');
            var count = 60; // 倒计时数量 一般为60秒!
            var timer = null; //定时

            //事件
            btn1.click(function () {
                var email=$('#useremail').val();
                console.log("成功返回结果:" + email);
                if (email=='') {
                    alert('请输入验证的邮箱');
                    return false;
                }
                if (!(/^[a-z0-9][\w.\-]*@[a-z0-9]+(\.[a-z]{2,5}){1,2}$/.test(email))) {
                    alert("您填入的邮箱格式不正确，请检查");
                    return false;
                }
                //Ajax发送短s信
                $.ajax({
                    type: 'get',
                    url: '{% url "myself:send_email" %}',
                    data: 'email=' + email,
                    success: function (msg) {
                        console.log("成功返回结果:" + msg);
                        obj = eval("(" + msg + ")");
                        if (obj.msg == "OK") {
                            {#$("#msg").html("发送成功")#}
                            alert('邮箱验证码发送成功')
                        } else {
                            {#$("#msg").html("发送失败")#}
                            alert("邮箱验证码发送失败")
                        }
                    },
                    error: function (resp) {
                        console.log(resp.status);
                        alert('连接后台失败')
                    }
                });
                //end 发送短信
                alert('邮箱验证码已发送');

                //禁用
                $(this).attr("disabled", 'true');
                var _this = $(this);
                //定时器实现时间每次减少1
                timer = setInterval(function () {
                    count--;
                    {#console.log("剩余时间:" + count);#}
                    if (count >= 0) {
                        //this表示对象!!!! 表示定时器!!!!
                        //this.innerHTML="时间剩余"+ count+"秒";
                        _this.html(count + "秒后重发")
                    } else {
                        _this.disabled = false;
                        clearInterval(timer);
                        _this.html("重新发送");
                        count = 5;
                        $('#sendsms').removeAttr("disabled")
                    }
                }, 1000);
            });
            //短信验证end
            //短信验证

        })
    </script>
        <script type="text/javascript">
            $(function(){
                $("#usercode").change(function () {
                    //验证ajax
                    email = $('#useremail').val();
                    code = $('#usercode').val();
                    $.ajax({
                        type: "get",
                        url: "{% url 'myself:check_email_user' %}",
                        data: "email=" + email + "&code=" + code,
                        success: function (result) {
                            console.log("Data Saved: " + result);
                            //已经为json
                            if (result.code == "200") {
                                alert('邮箱验证码验证通过');
                            } else {
                                {#$('#msg').html('手机验证码输入错误')#}
                                alert('验证码输入错误或您还未输入验证码,请您检查')
                            }
                            },
                        error: function (res) {
                            //状态码
                            console.log(res.status)
                        }
                    });
                })
            })

        </script>

	</head>

	<body>

        {% include 'person/top.html' %}
		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="am-cf am-padding">
						<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">绑定邮箱</strong> / <small>Email</small></div>
					</div>
					<hr/>
					<!--进度条-->
					<div class="m-progress">
						<div class="m-progress-list">
							<span class="step-1 step">
                                <em class="u-progress-stage-bg"></em>
                                <i class="u-stage-icon-inner">1<em class="bg"></em></i>
                                <p class="stage-name">验证邮箱</p>
                            </span>
							<span class="step-2 step">
                                <em class="u-progress-stage-bg"></em>
                                <i class="u-stage-icon-inner">2<em class="bg"></em></i>
                                <p class="stage-name">完成</p>
                            </span>
							<span class="u-progress-placeholder"></span>
						</div>
						<div class="u-progress-bar total-steps-2">
							<div class="u-progress-bar-inner"></div>
						</div>
					</div>
					<form class="am-form am-form-horizontal" method="post" action="{% url 'myself:myself_email_handle' %}">
                        {% csrf_token %}
						<div class="am-form-group">
							<label for="user-email" class="am-form-label">验证邮箱</label>
							<div class="am-form-content">
								<input type="email" id="useremail" placeholder="请输入邮箱地址" name="useremail">
							</div>
						</div>
						<div class="am-form-group code">
							<label for="user-code" class="am-form-label">验证码</label>
							<div class="am-form-content">
								<input type="tel" id="usercode" placeholder="验证码" name="yancode">
							</div>
{#							<a class="btn" href="javascript:void(0);" onclick="sendMobileCode();" id="sendMobileCode">#}
							<a class="btn" href="#" id="sendsmss">
								<div class="am-btn am-btn-danger">验证码</div>
							</a>
						</div>
						<div class="info-btn">
							<div class="am-btn am-btn-danger"><input type="submit" value="保存修改"></div>
						</div>
                        <span style="color: #c4ffbc;">{{ error }}</span>
					</form>

				</div>
				<!--底部-->
				<div class="footer">
					<div class="footer-hd">
						<p>
							<a href="#">恒望科技</a>
							<b>|</b>
							<a href="#">商城首页</a>
							<b>|</b>
							<a href="#">支付宝</a>
							<b>|</b>
							<a href="#">物流</a>
						</p>
					</div>
					<div class="footer-bd">
						<p>
							<a href="#">关于恒望</a>
							<a href="#">合作伙伴</a>
							<a href="#">联系我们</a>
							<a href="#">网站地图</a>
							<em>© 2015-2025 Hengwang.com 版权所有</em>
						</p>
					</div>
				</div>
			</div>

			<aside class="menu">
				<ul>
					<li class="person active">
						<a href="{% url 'myself:index' %}">个人中心</a>
					</li>
					<li class="person">
						<a href="#">个人资料</a>
						<ul>
							<li> <a href="{% url 'myself:myself_information' %}">个人信息</a></li>
							<li> <a href="{% url 'myself:myself_safety' %}">安全设置</a></li>
							<li> <a href="{% url 'myself:address' %}">收货地址</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的交易</a>
						<ul>
							<li><a href="{% url 'myself:myself_order' %}">订单管理</a></li>
							<li> <a href="{% url 'myself:myself_change' %}">退款售后</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的资产</a>
						<ul>
							<li> <a href="{% url 'myself:myself_coupon' %}">优惠券 </a></li>
							<li> <a href="{% url 'myself:myself_bonus' %}">红包</a></li>
							<li> <a href="{% url 'myself:myself_bill' %}">账单明细</a></li>
						</ul>
					</li>

					<li class="person">
						<a href="#">我的小窝</a>
						<ul>
							<li> <a href="{% url 'myself:myself_collection' %}">收藏</a></li>
							<li> <a href="{% url 'myself:myself_foot' %}">足迹</a></li>
							<li> <a href="{% url 'myself:myself_comment' %}">评价</a></li>
							<li> <a href="{% url 'myself:myself_news' %}">消息</a></li>
						</ul>
					</li>

				</ul>

			</aside>
		</div>

	</body>

</html>